package ACWing.mathematicalknowledge.质数;
//867. 分解质因数

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/9 19:51
 */
public class DecompositionPrimeFactor {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for (int i = 0; i < n; i++) {
            int x=sc.nextInt();
            divide(x);
        }
    }
    public static void divide(int n){
        for (int i = 2; i <= n/i; i++) {
            if(n%i==0){
                int s=0;
                while (n%i==0){
                    n=n/i;
                    s++;
                }
                System.out.println(i+" "+s);
            }
        }
        if(n>1){
            System.out.println(n+" "+1);
        }
        System.out.println();
    }
}
